﻿using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using Wq.Framework;
using Wq.Application;
using Wq.Model;
using Wq.ManagerService.Models;
using Wq.Framework.Base.Admin;

namespace Wq.Manager.API
{
    /// <summary>
    /// oss文件管理
    /// </summary>
    [Route("admin/file/oss")]
    public class OssFileController : ManagerBaseController
    {
        private readonly FileApplication fileApplication;

        /// <summary>
        /// oss文件管理
        /// </summary>
        /// <param name="fileApplication"></param>
        public OssFileController(FileApplication fileApplication) => this.fileApplication = fileApplication;

        /// <summary>
        /// 图片视频列表
        /// </summary>
        /// <param name="pageModel"></param>
        /// <returns></returns>
        [HttpPost("list")]
        public IActionResult List(PageModel<FileQuery> pageModel) => SuccessResult(fileApplication.List(pageModel));
       

        /// <summary>
        /// 上传图片文件
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>

        [HttpPost("image/upload")]
        [RequestSizeLimit(30_000_000)]
        public IActionResult UploadImage([FromForm] UploadImageCommand command) => SuccessResult(fileApplication.UploadImage(command));

        /// <summary>
        /// 上传视频文件
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost("video/upload")]
        [RequestSizeLimit(100_000_000)]
        public IActionResult UploadVideo([FromForm] UploadVideoCommand command) => SuccessResult(fileApplication.UploadVideo(command));


        /// <summary>
        /// 修改文件名称
        /// </summary>
        /// <param name="id"></param>
        /// <param name="name"></param>
        [HttpGet("setname")]
        public IActionResult SetImageName(long id, string name)
        {
            fileApplication.SetImageName(id, name);
            return SuccessResult();
        }

        /// <summary>
        /// 批量分组
        /// </summary>
        /// <param name="edior"></param>
        [HttpPost("setgroup")]
        public IActionResult SetGroup(BatchEdior edior)
        {
            fileApplication.SetGroup(edior);
            return SuccessResult();
        }

        /// <summary>
        /// 删除文件
        /// </summary>
        /// <param name="id"></param>
        [HttpPost("remove")]
        public IActionResult RemoveImage(BatchEdior edior)
        {
            fileApplication.RemoveImage(edior);
            return SuccessResult();
        }

        #region 图片分类

        /// <summary>
        /// 分类
        /// </summary>
        /// <returns></returns>
        [HttpGet("category/list")]
        public IActionResult CategoryList(FileType type) => SuccessResult(fileApplication.CategoryList(type));
      

        /// <summary>
        /// 编辑文件分类
        /// </summary>
        /// <param name="editor"></param>
        /// <returns></returns>
        [HttpPost("category/save")]
        public IActionResult CategorySave(CategoryEditor category)
        {
            fileApplication.CategorySave(category);
            return SuccessResult();
        }

        /// <summary>
        /// 修改文件分类名称
        /// </summary>
        /// <param name="id"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        [HttpGet("category/setname")]
        public IActionResult SetCategoryName(long id, string name)
        {
            fileApplication.SetCategoryName(id, name);
            return SuccessResult();
        }

        /// <summary>
        /// 删除文件分类
        /// </summary>
        /// <param name="id"></param>
        [HttpDelete("category/{id}")]
        public IActionResult RemoveCategory(long id)
        {
            fileApplication.RemoveCategory(id);
            return SuccessResult();
        }

        #endregion
    }
}
